package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ContactType;
import com.ruoyi.system.service.IContactTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 联系类型Controller
 * 
 * @author ruoyi
 * @date 2021-01-07
 */
@RestController
@RequestMapping("/system/type")
public class ContactTypeController extends BaseController
{
    @Autowired
    private IContactTypeService contactTypeService;

    /**
     * 查询联系类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContactType contactType)
    {
        startPage();
        List<ContactType> list = contactTypeService.selectContactTypeList(contactType);
        return getDataTable(list);
    }

    /**
     * 导出联系类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "联系类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ContactType contactType)
    {
        List<ContactType> list = contactTypeService.selectContactTypeList(contactType);
        ExcelUtil<ContactType> util = new ExcelUtil<ContactType>(ContactType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取联系类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{contId}")
    public AjaxResult getInfo(@PathVariable("contId") Long contId)
    {
        return AjaxResult.success(contactTypeService.selectContactTypeById(contId));
    }

    /**
     * 新增联系类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "新增联系类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContactType contactType)
    {
        return toAjax(contactTypeService.insertContactType(contactType));
    }

    /**
     * 修改联系类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "修改联系类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContactType contactType)
    {
        return toAjax(contactTypeService.updateContactType(contactType));
    }

    /**
     * 删除联系类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "删除联系类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contIds}")
    public AjaxResult remove(@PathVariable Long[] contIds)
    {
        return toAjax(contactTypeService.deleteContactTypeByIds(contIds));
    }
}
